package com.goldman.aplt.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @description：
 * @author： chenxiangxiang
 * @create： 2024/5/10 10:25
 */
public class SignUtil {
    public static String getDataStr(Map<String, Object> paramMap) {
        StringBuffer sb = new StringBuffer();
        List<String> keyList = new ArrayList<>();
        for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
            if ("sign".equals(entry.getKey())) {
                continue;
            }

            keyList.add(entry.getKey());
        }

        Collections.sort(keyList);
        for (String key : keyList) {
            String value = String.valueOf(paramMap.get(key));

            if(CommUtil.isNotNull(value)) {
                value = value.trim();
            }

            if (sb.length() != 0) {
                sb.append("&");
            }
            sb.append(key).append("=").append(value);
        }
        return sb.toString();
    }
}
